package reflect;

import reflect.annotations.AutoRunClass;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URISyntaxException;

public class Test3 {
    public static void main(String[] args) throws Exception {
        File dir = new File(Test3.class.getResource(".").toURI());
        File[] files = dir.listFiles(f->f.getName().contains(".class"));
        for (File file : files){
            String str = file.getName();
            String fileName = str.substring(0,str.lastIndexOf("."));
            Class cls = Class.forName(Test3.class.getPackage().getName()+"."+fileName);
            Object o = cls.newInstance();
            Method[] methods = cls.getDeclaredMethods();
            for (Method method : methods){
                if (cls.isAnnotationPresent(AutoRunClass.class)){
                    System.out.println(cls.getName()+"被@AutoRunClass标注了！");

                }else {
                    System.out.println(cls.getName()+"没有被@AutoRunClass标注了！");
                }

            }
        }
    }
}
